package com.three.iot.channel.impl.chinamobile;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.iot.model.v20180120.PubRequest;
import com.aliyuncs.iot.model.v20180120.PubResponse;
import com.aliyuncs.iot.model.v20180120.RRpcRequest;
import com.aliyuncs.iot.model.v20180120.RRpcResponse;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
import org.apache.commons.codec.binary.Base64;

/**
 * @author luiz
 * @Title: PubTest
 * @ProjectName iot-server
 * @Description: TODO
 * @date 2019-05-07 13:16
 */
public class RRPcTest {
    public static void main(String[] args) {
        // 阿里云accessKey
        String accessKey = "LTAIM4zSiZd7rMzu";
        // 阿里云accessSecret
        String accessSecret = "LiKB95DldnjMSGhzrUIcFEqmysb864";
        try {
            DefaultProfile.addEndpoint("cn-shanghai", "cn-shanghai", "Iot", "iot.cn-shanghai.aliyuncs.com");
        } catch (ClientException e) {
            e.printStackTrace();
        }
        IClientProfile profile = DefaultProfile.getProfile("cn-shanghai", accessKey, accessSecret);
        //初始化SDK客户端
        DefaultAcsClient client = new DefaultAcsClient(profile);

        RRpcRequest request = new RRpcRequest();
        request.setProductKey("a1BIyMhGr5p");
        request.setActionName("RRpc");
        request.setDeviceName("2019-001");
        // request.setTopic("");
        request.setRequestBase64Byte(Base64.encodeBase64String("hello world".getBytes()));
        request.setTimeout(5000);
        try {
            RRpcResponse response = client.getAcsResponse(request);
            System.err.println(response.getSuccess());
            System.err.println(response.getErrorMessage());
            System.err.println(response.getRrpcCode());
            System.err.println(response.getMessageId());
            System.err.println(response.getPayloadBase64Byte());
            System.err.println(response.getCode());
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }
}
